package com.asa.ui.E;

public class WinThePrizeExperiment {
	private int win;//统计中奖的次数

	public WinThePrizeExperiment(int number,double chance,int frequency) {
		play(number,chance,frequency);
	}
	//进行多少次为number的抽奖
	public void play(int number,double chance,int frequency){
		for(int i=0;i<frequency;i++){
			if(run(number,chance)){
				win++;
			}
		}
		System.out.println((double)win/frequency);
	}
	//开number个中奖的次数
	public boolean run(int number,double chance){
		for(int i=0;i<number;i++){
			if(Math.random()<=chance){
				return true;
			}
		}
		return false;
	}
	public static void main(String[] args) {
		new WinThePrizeExperiment(5,0.2,10000);
	}
}

